package diona.components

import xml.NodeSeq
import net.liftweb.util.CssSel
import net.liftweb.http.Templates
import diona.search.ProfileInfo

/**
 * User: anton
 * Date: 23.07.11 21:11
 */
class ProfileInfoComponent(profile: ProfileInfo) extends SnippetsUtil
{
  def render(): NodeSeq =
  {
    val template: NodeSeq = Templates(List("templates-hidden", "profileInfo")).open_!
    val result = bindCss(template)
    result
  }

  private lazy val bindCss: CssSel = {
    ".profile_name *" #> profile.name.getOrElse("") &
    ".profile_birthday *" #> formatDate(profile.birthday) &
    ".profile_city *" #> profile.city.getOrElse("") &
    ".profile_country *" #> profile.country.getOrElse("") &
    ".profile_links *" #> profile.profileLinks.map(link =>
      ".profile_link [href]" #> link &
      ".profile_link *" #> link
    ) &
    ".profile_weblogs *" #> profile.weblogs.map(link =>
      ".profile_weblog [href]" #> link &
      ".profile_weblog *" #> link
    )
  }
}

object ProfileInfoComponent
{
  def apply(profile: ProfileInfo): NodeSeq = new ProfileInfoComponent(profile).render()
}